<script>
import BookApi from "../../api/book";

export default {
  emits: ["search-result"],
  data() {
    return {
      keyword: ""
    };
  },
  methods: {
    async search() {
      try {
        const api = new BookApi();
        let res = await api.search(this.keyword);
        console.log(res);
        //从子组件向父组件传递数据
        this.$emit("search-result", res.data);
      } catch (err) {
        console.error(err);
        this.$myMessageBox("应用服务器访问错误！");
      }
    }
  }
};
</script>

<template>
  <div class="book-search">
    <input type="text " title="输入搜索关键字" placeholder="书名或作者名" v-model="keyword" />
    <button @click="search">搜索</button>
  </div>
</template>

<style scoped></style>
